// 双向链表

typedef struct DuLNode
{
    int data;
    struct DuLNode *prior;
    struct DuLNode * next;
}DuLNode, *DuLinkList;

enum Status
{
    OK,
    ERROR,
};

Status ListInsert_DuL(DuLinkList &L, int i, int e)
{
    DuLNode *p = L->next;
    int j = 0;

    while(p && j < i)
    {
        p = p->next;
        j++;
    }

    if(!p || j >= i)
    {
        return ERROR;
    }

    DuLNode *s = new DuLNode;

    s->data = e;

    s->next = p->next;
    s->prior = p;
    p->next->prior = s;
    p->next = s;

    return OK;
}

Status ListDelete_DuL(DuLinkList &L, int i, int &e)
{
    DuLNode *p = L->next;
    int j = 0;

    while(p && j < i)
    {
        p = p->next;
        j++;
    }

    if(!p || j >= i)
    {
        return ERROR;
    }

    e = p->data;

    DuLNode *pri = p->prior;
    DuLNode *nex = p->next;

    pri->next = nex;
    nex->prior = pri;

    delete(p);

    return OK;
}
